﻿using PersistentObject.Common.DataConvertors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace PersistentObject.Common.Schema
{
    public class ColumnInfo
    {
        public ColumnInfo()
        {
        }

        /// <summary>
        /// Indicate the table info of this column info belonging to 
        /// </summary>
        public TableInfo TableInfo { get; internal set; }

        /// <summary>
        /// Indicate the property info of this column info belonging to
        /// </summary>
        public PropertyInfo Property { get; internal set; }

        /// <summary>
        /// Indicate the name of this column info
        /// </summary>
        public string Name { get; internal set; }

        public DataConvertor Convertor { get; internal set; }

        /// <summary>
        /// Indicate whether this column info can load data from database
        /// </summary>
        public bool Load { get; internal set; }

        /// <summary>
        /// Indicate whether this column info can save data into database
        /// </summary>
        public bool Save { get; internal set; }

        public bool IsKeyColumn { get; internal set; }

        public bool IsAutoGenerated { get; internal set; }

        public bool IsForeignKeyColumn { get; internal set; }

        /// <summary>
        /// Indicate the table info of the foreign table
        /// </summary>
        public TableInfo ForeignTableInfo { get; internal set; }

        public override string ToString()
        {
            return string.Format("{0}.{1}, key:{2}, foreign:{3}, ", TableInfo.Name, Name, IsKeyColumn,
                IsForeignKeyColumn ? ForeignTableInfo.Name : "");
        }
    }
}
